import db from '../../utils/dbconf';
import makeres from '../../utils/res';
import { TargetDataNoneError } from '../../utils/classModal';

export const TABLE_NAME = 'AUTH_CONF';

export default {
	add: async ({ body: data }, res) => {
		const id = await db.table(TABLE_NAME).add(data);
		return res.send(makeres.success({ id }));
	},
	change: async ({ params: { id }, body: data }, res) => {
		const ok = await db.table(TABLE_NAME).where({ id }).update(data);
		if (!ok) throw new TargetDataNoneError();
		return res.send(makeres.putsuccess());
	},
	delete: async ({ params: { id } }, res) => {
		const ok = await db.table(TABLE_NAME).where({ id }).delete();
		if (!ok) throw new TargetDataNoneError();
		return res.send(makeres.deletesuccess());
	},
};
